package BookCreated;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import BookDB.h2DAO;
import BookDB.h2DB;
import Loginout.UserBean;

import java.util.List;

@SuppressWarnings("unused")
@WebServlet("/createbook")
public class CreateBook extends HttpServlet {
	private static final long serialVersionUID = 1L;

	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		HttpSession session = request.getSession();
		UserBean UB = (UserBean) session.getAttribute("ub");

		if (UB == null) {
			response.sendRedirect("error.html");
		} else {
			response.setContentType("text/html;charset=UTF-8");
			request.setCharacterEncoding("UTF-8");

			String isbn = request.getParameter("ibsn");

			Books b = new Books();
			try {
				b.setBookID(h2DAO.getTableID());

				session.setAttribute("sessionBook", b);
				// Books book = (Books) session.getAttribute("sessionBook");

			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}

			request.setAttribute("ebook", b);
			request.getRequestDispatcher("EditBookPage.jsp").forward(request,
					response);
		}
	}
}
